package impl

import (
	"context"
	"gitee.com/kordar/goadmin/admin/service"
	"gitee.com/kordar/goadmin/reader"
	"github.com/kordar/ginsys/resource"
	"github.com/kordar/gocrud"
	gocrudgorm "github.com/kordar/gocrud-gorm"
	"gorm.io/gorm"
	"labelsys/dataset/form"
	"labelsys/dataset/model"
	"labelsys/dataset/vo"
)

type DatasetLabelServiceImpl struct {
	*gocrud.CommonResourceService
	db          *gorm.DB
	dictService service.DictService
}

func NewDatasetLabelService(db *gorm.DB, dictService service.DictService) *DatasetLabelServiceImpl {
	return &DatasetLabelServiceImpl{db: db, dictService: dictService}
}

func (service DatasetLabelServiceImpl) ResourceName() string {
	return "dataset-label"
}

func (service DatasetLabelServiceImpl) Configs(ctx context.Context) map[string]interface{} {
	//locale := resp.GetLocale(ctx)
	return map[string]interface{}{}
}

func (service DatasetLabelServiceImpl) Search(body gocrud.SearchBody) gocrud.SearchVO {
	searchBody := gocrudgorm.NewGormSearchBody(body)
	db := searchBody.GormQuery(service.db, nil).Model(&model.LabelsysDatasetLabel{})
	queryReader := reader.NewQueryReader(db, int(body.Page), int(body.PageSize))
	var datasetLabelVOS []*vo.DatasetLabelVO
	return queryReader.SearchVO(&datasetLabelVOS, nil)
}

func (service DatasetLabelServiceImpl) Create(body gocrud.FormBody) (interface{}, error) {
	return resource.Create(body, service.db, &form.DatasetLabelForm{}, nil, nil)
}

func (service DatasetLabelServiceImpl) Update(body gocrud.FormBody) (interface{}, error) {
	return resource.Updates(body, service.db, &form.DatasetLabelForm{}, nil, func(v interface{}) error {
		return nil
	})
}

func (service DatasetLabelServiceImpl) Remove(body gocrud.RemoveBody) error {
	return body.Delete(&model.LabelsysDatasetLabel{}, service.db, nil)
}
